/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package mtbldomain.impl;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

import mtbldomain.MetricDescriptionType;
import mtbldomain.MetricResultsType;
import mtbldomain.MtblDomainPackage;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Metric Results Type</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link mtbldomain.impl.MetricResultsTypeImpl#getMetricDescription <em>Metric Description</em>}</li>
 *   <li>{@link mtbldomain.impl.MetricResultsTypeImpl#getIsComparation <em>Is Comparation</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class MetricResultsTypeImpl extends EObjectImpl implements MetricResultsType {
	/**
	 * The cached value of the '{@link #getMetricDescription() <em>Metric Description</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMetricDescription()
	 * @generated
	 * @ordered
	 */
	protected EList<MetricDescriptionType> metricDescription;

	/**
	 * The default value of the '{@link #getIsComparation() <em>Is Comparation</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIsComparation()
	 * @generated
	 * @ordered
	 */
	protected static final String IS_COMPARATION_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getIsComparation() <em>Is Comparation</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIsComparation()
	 * @generated
	 * @ordered
	 */
	protected String isComparation = IS_COMPARATION_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected MetricResultsTypeImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return MtblDomainPackage.Literals.METRIC_RESULTS_TYPE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<MetricDescriptionType> getMetricDescription() {
		if (metricDescription == null) {
			metricDescription = new EObjectContainmentEList<MetricDescriptionType>(MetricDescriptionType.class, this, MtblDomainPackage.METRIC_RESULTS_TYPE__METRIC_DESCRIPTION);
		}
		return metricDescription;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getIsComparation() {
		return isComparation;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setIsComparation(String newIsComparation) {
		String oldIsComparation = isComparation;
		isComparation = newIsComparation;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MtblDomainPackage.METRIC_RESULTS_TYPE__IS_COMPARATION, oldIsComparation, isComparation));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case MtblDomainPackage.METRIC_RESULTS_TYPE__METRIC_DESCRIPTION:
				return ((InternalEList<?>)getMetricDescription()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case MtblDomainPackage.METRIC_RESULTS_TYPE__METRIC_DESCRIPTION:
				return getMetricDescription();
			case MtblDomainPackage.METRIC_RESULTS_TYPE__IS_COMPARATION:
				return getIsComparation();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case MtblDomainPackage.METRIC_RESULTS_TYPE__METRIC_DESCRIPTION:
				getMetricDescription().clear();
				getMetricDescription().addAll((Collection<? extends MetricDescriptionType>)newValue);
				return;
			case MtblDomainPackage.METRIC_RESULTS_TYPE__IS_COMPARATION:
				setIsComparation((String)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case MtblDomainPackage.METRIC_RESULTS_TYPE__METRIC_DESCRIPTION:
				getMetricDescription().clear();
				return;
			case MtblDomainPackage.METRIC_RESULTS_TYPE__IS_COMPARATION:
				setIsComparation(IS_COMPARATION_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case MtblDomainPackage.METRIC_RESULTS_TYPE__METRIC_DESCRIPTION:
				return metricDescription != null && !metricDescription.isEmpty();
			case MtblDomainPackage.METRIC_RESULTS_TYPE__IS_COMPARATION:
				return IS_COMPARATION_EDEFAULT == null ? isComparation != null : !IS_COMPARATION_EDEFAULT.equals(isComparation);
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (isComparation: ");
		result.append(isComparation);
		result.append(')');
		return result.toString();
	}
	
	public List<MetricDescriptionType> getProjectsInMetricResultType() {
		List<MetricDescriptionType> metDescriptions = this.getMetricDescription();
		List<MetricDescriptionType> projects = new LinkedList<MetricDescriptionType>();
		for (MetricDescriptionType metricDescription : metDescriptions) {
			if(metricDescription.getKind() == MetricDescriptionType.PROJECT_KIND){
				projects.add(metricDescription);
			}
		}
		return projects;
	}

} //MetricResultsTypeImpl
